package net.sourceforge.peertwitter.mbpast;

import rice.p2p.commonapi.Id;
import rice.p2p.commonapi.NodeHandle;

public class ReplicaSource {

	private final NodeHandle node;
	private final ReplicationTimestamp timestamp;
	private final Id targetId;

	public ReplicaSource(NodeHandle sourceNode, ReplicationTimestamp timestamp, Id targetId) {
		this.node = sourceNode;
		this.timestamp = timestamp;
		this.targetId = targetId;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((node == null) ? 0 : node.hashCode());
		result = prime * result
				+ ((targetId == null) ? 0 : targetId.hashCode());
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		ReplicaSource other = (ReplicaSource) obj;
		if (node == null) {
			if (other.node != null) {
				return false;
			}
		} else if (!node.equals(other.node)) {
			return false;
		}
		if (targetId == null) {
			if (other.targetId != null) {
				return false;
			}
		} else if (!targetId.equals(other.targetId)) {
			return false;
		}
		return true;
	}



	@Override
	public String toString() {
		return "ReplicaSource [node=" + node + ", timestamp=" + timestamp
				+ ", targetId=" + targetId + "]";
	}

	public NodeHandle getNode() {
		return node;
	}

	public ReplicationTimestamp getTimestamp() {
		return timestamp;
	}

	public Id getTargetId() {
		return targetId;
	}

}
